<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <div id="mess">正在连接...</div>
    <div class="kuang">
        <div class="value" id="value1">小明小明</div>
        <div class="value" id="value2">大胸大胸</div>
        <div class="value" id="value3">小张小张</div>
    </div>
    
</body>
<script src="./jquery.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/socket.io/2.1.1/socket.io.dev.js"></script>
<script>
    var socket = io('ws://10.220.115.14:9000');
    socket.on('connect', function() {
        socket.emit('open', {msg:"连接成功"}); //向服务器发送消息
        console.log("与服务器连接成功");
    });
    socket.on('news',function(data){
        console.log(data);
    });
    $('#value1').click(function () {
        socket.emit('message', {rp:"fine,thank you"}); //向服务器发送消息
    })
    // var mess = document.getElementById("mess");
    // if(window.WebSocket){
    //     var ws = new WebSocket('ws://10.220.115.14:9000');
    //     ws.onopen = function(e){
    //         console.log("连接服务器成功");
    //         ws.send("game1");
    //     }
    //     ws.onclose = function(e){
    //         console.log("服务器关闭");
    //     }
    //     ws.onerror = function(){
    //         console.log("连接出错");
    //     }
    //     ws.onmessage = function(e){
    //         mess.innerHTML = "连接成功"
    //         document.querySelector(".kuang").onclick = function(e){
    //             var time = new Date();
    //             ws.send(time + "  game1点击了“" + e.target.innerHTML+"”");
    //         }
    //     }
    // }
</script>
</html>